<?php

use Illuminate\Support\Facades\Response;

if (!function_exists('json')) {
    /**
     * 获取\think\response\Json对象实例
     * @param mixed $data    返回的数据
     * @param int   $code    状态码
     * @param array $header  头部
     * @param array $options 参数
     * @return \Illuminate\Http\Response
     */
    function json($data = [], $code = 200, $header = [])
    {
        return Response::make($data, $code,$header);
    }
}
if (!function_exists('getChineseNameAbbreviation')) {

    function getChineseNameAbbreviation($name) {
        $length = mb_strlen($name);
        $abbreviation = '';
        for ($i = 0; $i < $length; $i++) {
            $char = mb_substr($name, $i, 1);
            // 转换为拼音
            $pinyin = iconv('UTF-8', 'GBK//IGNORE', $char);
            $pinyin = strtoupper(trim($pinyin));
            // 取每个汉字拼音的首字母
            $abbreviation .= $pinyin ? substr($pinyin, 0, 1) : $char;
        }
        return preg_replace('/[^A-Za-z0-9]/', '', $abbreviation);
    }
}


